from google.appengine.ext import db

class Result(db.Model):
    search_string = db.StringProperty(required=True)
    images = db.StringListProperty(required=True)
    
def AddResult(ss, ilist):
    result = GetResult(ss)
    
    if result is None:
        result = Result(search_string=ss, images=["http://re.flect.net/"+i.img['src'] for i in ilist])
        result.put()
    
    return result

def GetResult(ss):
    query = Result.gql('WHERE search_string = :1', ss)
    results = query.fetch(1)
    
    if len(results) == 1:
        return results[0]
    else:
        return None
        
def GetResultImages(ss):
    item = GetResult(ss)
    if item is None:
        return None
        
    return item.images